package com.kalaqia.image.library;

import android.content.Context;
import android.support.annotation.NonNull;

import com.kalaqia.image.GlideLoader;

public class ImageLoaderManager implements IImageLoaderStrategy {

    private static ImageLoaderManager mInstance;

    private IImageLoaderStrategy loaderStrategy = new GlideLoader();

    private ImageLoaderManager() {
    }

    public void setLoaderStrategy(IImageLoaderStrategy loaderStrategy) {
        this.loaderStrategy = loaderStrategy;
    }

    public static ImageLoaderManager getInstance() {
        if (mInstance == null) {
            synchronized (ImageLoaderManager.class) {
                if (mInstance == null) {
                    mInstance = new ImageLoaderManager();
                    return mInstance;
                }
            }
        }
        return mInstance;
    }

    @Override
    public void showImage(@NonNull ImageLoaderOptions options) {
        if (loaderStrategy != null) {
            loaderStrategy.showImage(options);
        }
    }

    @Override
    public void cleanMemory(Context context) {
        if (loaderStrategy != null) {
            loaderStrategy.cleanMemory(context);
        }
    }
}
